#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <stdlib.h>
#include <graphics.h>
#define callmouse() int86(0x33,&reg,&reg)


union REGS reg;
char mouse_state='n';
int x_offset=0,y_offset=0;
unsigned int x,y,size;
char x0,y0;
int wid,hei;
void *arrow;

void arrowpoint(char color)
{
	int curse[]={x,y,x+14,y+8,x+9,y+6,x+18,y+15,
					x+15,y+18,x+6,y+9,x+8,y+14};
	setcolor(color);	setfillstyle(1,color); fillpoly(7,curse);
}

void savearrow()
{
	disable();
	size=imagesize(x,y,x+18,y+18);
	arrow=malloc(size);getimage(x,y,x+18,y+18,arrow);
	enable();
}

void restorearrow()
{
	disable();
	putimage(x,y,arrow,0);free(arrow);
	enable();
}


void Getmouse()
{
	int xx,yy;
	reg.x.ax=0x0b;
	callmouse();
	xx=(int)reg.x.cx+x_offset;
	yy=(int)reg.x.dx+y_offset;
	x_offset=xx%16;
	y_offset=yy%16;
	xx=xx/16;
	yy=yy/16;
	if(xx|yy){
		restorearrow();
		x0 +=xx;
		if(x0<0) x0=0;
		if(x0>wid/22) x0=wid/22;
		y0 +=yy;
		if(y0<0) y0=0;
		if(y0>hei/22) y0=hei/22;
		x=x0*22; y=y0*22; savearrow();arrowpoint(WHITE);
		}
	reg.x.ax=5; reg.x.bx=0;
	callmouse();
}

void main(void)
{   int gdriver=DETECT,gmode;
	registerbgidriver(EGAVGA_driver);
	initgraph(&gdriver,&gmode,"");
	wid=getmaxx();
	hei=getmaxy();
	while(!kbhit())
	{
		Getmouse();
	}
}
